var express = require('express');
var http= require('http');
var app = express();

app.use(express.static(__dirname))

app.get('/proxy', (request, response)=>{
    var url = request.query.url
    // 向url发出请求
    http.get(url, res=>{
        // data事件会在数据接收过程中，每收到一段数据就触发一次，接收到的数据被传入回调函数。
        res.on("data", data=>{
            // response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
            // response.end(data)
            response.send(data);
        })
    })
})



app.listen(3000, function () {
    console.log('Requester with proxy is listening on port 3000');
});
